<template>
  <div class="Index">
    <router-view></router-view>

    <div style="height:50px;width: 100vw"></div>
    <div class="tab">
      <div :class="type == 1 ? 'tab-color' : ''" to="/" @click="switchType(1)">
        首页
      </div>
      <div
        :class="type == 2 ? 'tab-color' : ''"
        to="/about"
        @click="switchType(2)"
      >
        新车报价
      </div>
      <!--            <div :class="type==3?'tab-color':''" to="/" @click="switchType(3)">二手车报价</div>-->
      <div :class="type == 4 ? 'tab-color' : ''" to="/" @click="switchType(4)">
        我的
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Watch } from 'vue-property-decorator';
import Sence from '../sence/Sence';

@Component({
  components: {},
})
export default class Index extends Sence {
  public type: any = 1;

  @Watch('$route')
  private routeEvent(n: any, o: any): void {
    switch (n.path) {
      case '/':
        this.type = 1;
        break;
      case '/car':
        this.type = 2;
        break;
      case '/mine':
        this.type = 4;
        break;
    }
  }

  public mounted(): void {
    switch (this.$route.path) {
      case '/':
        this.type = 1;
        break;
      case '/car':
        this.type = 2;
        break;
      case '/mine':
        this.type = 4;
        break;
    }
  }

  public switchType(data: any): void {
    const that = this;
    if (data != that.type) {
      switch (data) {
        case 1:
          if (this.type != 1) {
            that.type = 1;
            this.$router.push('/');
          }
          break;

        case 2:
          if (this.type != 2) {
            that.type = 2;
            this.$router.push('/car');
          }
          break;
        // case 3:
        //     that.type = 3;
        //     this.$router.push("/carused");
        //     break;
        case 4:
          if (this.type != 4) {
            that.type = 4;
            this.$router.push('/mine');
          }
          break;
      }
    }
  }
}
</script>

<style scoped lang="stylus">
* {
  padding: 0;
  margin: 0;
}

.tab {
  display: flex;
  flex-direction: row;
  position: fixed;
  bottom: 0;
  width: 100vw;
  justify-content: space-around;
  align-items: center;
  height: 50px;
  background: #ddd;

  div {
    font-weight: bold;
  }
}

.tab-color {
  color: red;
}
</style>
